import { useInfiniteScroll, useScroll } from '@vueuse/core'
import { ref, watch } from 'vue'
export const listenScrollToBottom = (el, cb) => {
  useInfiniteScroll(
    el,
    () => {
      cb()
    },
    {
      distance: 30, // 距离底部 10px 时触发加载更多
      interval: 300
    }
  )
}

export const showScrollTopBtn = ref(false)
export const isShowScrollTopButton = (el) => {
  const { y } = useScroll(el)
  watch(
    () => y.value,
    (newValue) => {
      if (newValue > 300) {
        showScrollTopBtn.value = true
      } else {
        showScrollTopBtn.value = false
      }
    }
  )
}
export const scrolltoTop = (el) => {
  if (el) {
    el.scrollTo({ top: 0, behavior: 'smooth' })
  }
}
